<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>膜丝抽检记录</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/layui.css"  media="all">
	<link rel="stylesheet" href="${pageContext.request.contextPath }/assets/css/toastr.min.css"  media="all">
	
	<script type="text/javascript" src="${pageContext.request.contextPath }/assets/js/jquery.min.js" charset="utf-8"></script>
	<style type="text/css">
		.layui-form-label{
			width: 100px;
		}
	</style>
</head>
<body>
<div class="demoTable" style="padding:10px 0 0 15px">
    <div class="layui-inline">
       	<input class="layui-input" id="keyword" style="width: 300px" placeholder="请输入膜丝名称或检验批次序号查询"/>
    </div>
    <button class="layui-btn layui-btn-blue" style="margin: 0 0 0 10px" data-type="reload"><i class="layui-icon layui-icon-search">  搜索</i></button>
    <button class="layui-btn layui-btn-blue" style="float:right;margin-right: 20px;" id="statistics"><i class="layui-icon layui-icon-layouts">  查看统计表</i></button>
</div>
<!-- 上表 -->
<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-blue" lay-event="add"><i class="layui-icon layui-icon-add-1">  新增</i></button>
		<button class="layui-btn layui-btn-blue" lay-event="delete"><i class="layui-icon layui-icon-delete">  批量删除</i></button>
	</div>
</script>
<h2 style="text-align: center;color:#666">膜丝抽检单</h2>
<table class="layui-hide" id="msSpotCheck" lay-filter="msSpotCheck"></table>
<script type="text/html" id="barDemo">
	<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<!-- 隐藏域 -->
<input id="orderNumberText" type="text" class="layui-hide">
<!-- 下表 -->
<script type="text/html" id="toolbarDemoDetails">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-blue" lay-event="addDetails"><i class="layui-icon layui-icon-add-1">  新增</i></button>
	</div>
</script>
<h2 style="text-align: center;color:#666" class="layui-hide" id="detailsTitle">抽检单详情</h2>
<table class="layui-hide" id="msSpotCheckDetails" lay-filter="msSpotCheckDetails"></table>
<script type="text/html" id="barDemoDetails">
	<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delDetails">删除</a>
</script>

<script src="${pageContext.request.contextPath }/assets/layui.js" charset="utf-8"></script>
<script src="${pageContext.request.contextPath }/assets/layui.all.js"></script>
<script src="${pageContext.request.contextPath }/assets/js/toastr.min.js" charset="utf-8"></script>
<script type="text/javascript">
//日期格式转换1
function createTime(v){
	var date = new Date(v);
    var y = date.getFullYear();
    var M = date.getMonth()+1;
    M = M<10?'0'+M:M;
    var d = date.getDate();
    d = d<10?("0"+d):d;
    var h = date.getHours();
    h = h<10?("0"+h):h;
    var m = date.getMinutes();
    m = m<10?("0"+m):m;
    var str = y+"-"+M+"-"+d+" "+h+":"+m;
    return str;
}
//日期格式转换2
function date2String(timestamp){
	var d = new Date(timestamp);
	var date = (d.getFullYear()) + "-" + 
       (d.getMonth() + 1<10?"0"+(d.getMonth() + 1):d.getMonth() + 1) + "-" +
       (d.getDate()<10?"0"+d.getDate():d.getDate()) + " " + 
       (d.getHours()<10?"0"+d.getHours():d.getHours()) + ":" + 
       (d.getMinutes()<10?"0"+d.getMinutes():d.getMinutes()) + ":" + 
       (d.getSeconds()<10?"0"+d.getSeconds():d.getSeconds());
       
       return date;
}
layui.use(['table','layer','upload','form','laydate'], function(){
	var table = layui.table;
	var layer = layui.layer,
    form = layui.form,laydate=layui.laydate;
	
	var $ = layui.jquery, active = {
			reload:function () {
				var keyword = $("#keyword").val();
				table.reload('contenttable',{
					method:'get',
					where:{keyword:keyword}
					,page: {
						curr: 1 //重新从第 1 页开始
					}
				});
			}
		}
	$('.layui-btn').on('click', function(){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });
	table.render({
	    elem: '#msSpotCheck'
	    ,url:'${pageContext.request.contextPath }/msSpotCheck/selectMsSpotCheckList.do'
	    ,toolbar: '#toolbarDemo'
	    ,title: '膜丝抽检单'
	    ,id :'contenttable'
	    ,limits:[10,20,30]
	    ,cols: [[
		  {type: 'checkbox', fixed: 'left',width:50}
		  ,{field:'', title:'序号', sort: true, type:'numbers', width: 60}
		  ,{field:'orderNumber', title:'检验批次序号'}
	      ,{field:'msName', title:'膜丝名称'}
	      ,{field:'msStandard', title:'膜丝规格'}
	      ,{field:'checkPerson', title:'检验员'}
	      ,{field:'checkDate', title:'检验时间',sort:true,templet:function(row){
	    	  return date2String(row.checkDate.time);
	      }}
	      ,{fixed: 'right', title:'操作', toolbar: '#barDemo',width:150}
	    ]]
	    ,page: true
	});
  
	//头工具栏事件
	table.on('toolbar(msSpotCheck)', function(obj){
		var checkStatus = table.checkStatus(obj.config.id);
		var content = 	'<form class="layui-form layui-card-body" id="addFormId">'+
							'<div class="layui-form-item"><label class="layui-form-label">检验批次序号</label><input class="layui-input" lay-verify="orderNumber" id="orderNumber" name="orderNumber" type="text" value="" style="width:300px;"></div>'+
							'<div class="layui-form-item"><label class="layui-form-label">膜丝名称</label>'+
								'<div class="layui-input-inline" style="width:300px">'+
									'<select class="layui-select" id="msName" name="msName" lay-filter="msName">'+
										'<option value="">--请选择--</option>'+
									'</select>'+
								'</div>'+
							'</div>'+
							'<div class="layui-form-item"><label class="layui-form-label">膜丝规格</label>'+
								'<div class="layui-input-inline" style="width:300px">'+
									'<select class="layui-select" id="msStandard" name="msStandard" lay-filter="msStandard">'+
										'<option value="">--请选择--</option>'+
									'</select>'+
								'</div>'+
							'</div>'+
							'<div class="layui-form-item"><label class="layui-form-label">检验时间</label>'+
								'<input class="layui-input layui-input-inline" lay-verify="checkDate" id="checkDate" name="checkDate" type="text" value="" style="width:300px;">'+
								'<div class="layui-inline" style="margin-top: 12px;">'+
									'<font style="color:red; font-size: 24px;">*</font>'+
								'</div>'+	
							'</div>'+
					  		
							'<div class="layui-form-item"><div class="layui-input-block">'+
								'<button id="subBtn1" class="layui-btn layui-btn-blue" lay-submit lay-filter="addform">提交</button><button type="reset" id="addReset" class="layui-btn layui-btn-primary" style="margin-left:140px">重置</button>'+
							'</div></div>'+
						'</form>';
	    switch(obj.event){
	    	case 'add':
	    		layer.open({
					  type: 1 		//Page层类型
					  ,area: ['500px', '400px'] //宽  高
					  ,title: '新增'
					  ,shade: 0.1 	//遮罩透明度
					  ,maxmin: true //允许全屏最小化
					  ,anim: 1 		//0-6的动画形式，-1不开启
					  ,content: content
					  ,success:function(layero, index){
						  $.ajax({
							  type:'post'
							  ,url:'${pageContext.request.contextPath }/msSpotCheck/selectMsNameList.do'
							  ,dataType:'json'
							  ,success:function(res){
								  var length = res.data.length;
								  $("#msName").find("option").not(":first").remove();
								  for(var x = 0; x < length;x++){
									  $("#msName").append(
										'<option value="'+res.data[x].paname+'">'+res.data[x].paname+'</option>'	  
									  );
								  }
								  form.render();
								 
							  }
						  })
						  form.on('select(msName)', function(data){
						    	var msName = $("#msName").val();
						    	$.ajax({
						    		type:'post'
						    		,url:'${pageContext.request.contextPath}/msSpotCheck/selectMsStandardListByName.do'
						    		,data:{'msName':msName}
						    		,dataType:'json'
						    		,success:function(res1){
						    			var length = res1.data.length;
						    			$("#msStandard").find("option").not(":first").remove();
						    			for(var x = 0; x < length;x++){
							    			$("#msStandard").append(
												'<option value="'+res1.data[x].pamodel+'">'+res1.data[x].pamodel+'</option>'	  
											);
						    			}
						    			form.render();
						    		}
						    	})
						    });
						  //日期
						  laydate.render({
							   elem: '#checkDate'
							   ,type: 'datetime'
							});
					  }
				});
	      	break;
	    	case 'delete':
	        	var data = checkStatus.data;
	        	var idArr = new Array();
	        	if(data.length==0){
	        		toastr.warning("请至少选择一条记录！");
	        	}
	        	var idArr = new Array();
	        	for(var i=0;i<data.length;i++){
	        		idArr[i] = data[i].msId;
	    		    layer.confirm('确定删除吗？', function(index){
	    			    $.ajax({
	    			    	type:'post',
	    			    	url:'${pageContext.request.contextPath }/msSpotCheck/delMsSpotCheckArr.do',
	    			    	data:{"idArr":idArr},
	    			    	success:function(num){
	    			    		if(num>0){
	    			    			toastr.success("删除了"+num+"条数据！");
	    			    			setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
	    								//关闭模态框
	    								// 父页面刷新
	    								window.location.reload();  
	    							},2000);
	    			    		}else{
	    			    			toastr.warning("删除失败！");
	    			    		}
	    			    	}
	    			    		
	    			    })
	    			    layer.close(index);
	    			  });
	        	}
	      	break;
	    };
	});
  
	//监听行工具事件
	table.on('tool(msSpotCheck)', function(obj){
		var data = obj.data;
		if(obj.event === 'del'){
		  layer.confirm('确定删除吗？', function(index){
			var idArr = new Array();
		    var msId = data.msId;
		    idArr[0] = msId;
		    $.ajax({
		    	type:'post',
		    	url:'${pageContext.request.contextPath }/msSpotCheck/delMsSpotCheckArr.do',
		    	data:{"idArr":idArr},
		    	success:function(data){
		    		if(data>0){
		    			toastr.success("删除成功！");
		    			setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
							//关闭模态框
							// 父页面刷新
							window.location.reload();  
						},2000);
		    		}else{
		    			toastr.warning("删除失败！");
		    		}
		    	}
		    		
		    })
		    layer.close(index);
		  });
		} else if(obj.event === 'edit'){
			var content1 = '<form class="layui-form layui-card-body" id="editFormId">'+
								'<input class="layui-input" lay-verify="msId" name="msId" style="display:none" type="text" value="'+data.msId+'">'+
								'<div class="layui-form-item"><label class="layui-form-label">检验批次序号</label><input class="layui-input" lay-verify="orderNumber" id="orderNumber" name="orderNumber" type="text" value="'+data.orderNumber+'" style="width:300px;"></div>'+
								'<div class="layui-form-item"><label class="layui-form-label">膜丝名称</label>'+
									'<div class="layui-input-inline" style="width:300px">'+
										'<select class="layui-select" id="msName" name="msName" lay-filter="msName">'+
											'<option value="'+data.msName+'">'+data.msName+'</option>'+
										'</select>'+
									'</div>'+
								'</div>'+
								'<div class="layui-form-item"><label class="layui-form-label">膜丝规格</label>'+
									'<div class="layui-input-inline" style="width:300px">'+
										'<select class="layui-select" id="msStandard" name="msStandard" lay-filter="msStandard">'+
											'<option value="'+data.msStandard+'">'+data.msStandard+'</option>'+
										'</select>'+
									'</div>'+
								'</div>'+
								'<div class="layui-form-item"><label class="layui-form-label">检验时间</label>'+
									'<input class="layui-input layui-input-inline" lay-verify="checkDate" id="checkDate" name="checkDate" type="text" value="'+date2String(data.checkDate.time)+'" style="width:300px;">'+
									'<div class="layui-inline" style="margin-top: 12px;">'+
										'<font style="color:red; font-size: 24px;">*</font>'+
									'</div>'+	
								'</div>'+
								'<div class="layui-form-item"><div class="layui-input-block">'+
									'<button class="layui-btn layui-btn-blue" lay-submit lay-filter="editform">提交</button><button type="reset" id="editReset" class="layui-btn layui-btn-primary" style="margin-left:140px">重置</button>'+
								'</div></div>'+
							'</form>';
			layer.open({
				  type: 1 		//Page层类型
				  ,area: ['500px', '400px'] //宽  高
				  ,title: '修改'
				  ,shade: 0.1 	//遮罩透明度
				  ,maxmin: true //允许全屏最小化
				  ,anim: 1 		//0-6的动画形式，-1不开启
				  ,content: content1
				  ,success:function(layero, index){
					  $.ajax({
						  type:'post'
						  ,url:'${pageContext.request.contextPath }/msSpotCheck/selectMsNameList.do'
						  ,dataType:'json'
						  ,success:function(res){
							  var length = res.data.length;
							  $("#msName").find("option").not(":first").remove();
							  for(var x = 0; x < length;x++){
								  $("#msName").append(
									'<option value="'+res.data[x].paname+'">'+res.data[x].paname+'</option>'	  
								  );
							  }
							  form.render();
							 
						  }
					  })
					  form.on('select(msName)', function(data){
					    	var msName = $("#msName").val();
					    	$("#msStandard").empty();
					    	$("#msStandard").append(
									'<option value="">--请选择--</option>'	  
								);
					    	$.ajax({
					    		type:'post'
					    		,url:'${pageContext.request.contextPath}/msSpotCheck/selectMsStandardListByName.do'
					    		,data:{'msName':msName}
					    		,dataType:'json'
					    		,success:function(res1){
					    			var length = res1.data.length;
					    			$("#msStandard").find("option").not(":first").remove();
					    			for(var x = 0; x < length;x++){
						    			$("#msStandard").append(
											'<option value="'+res1.data[x].pamodel+'">'+res1.data[x].pamodel+'</option>'	  
										);
					    			}
					    			form.render();
					    		}
					    	})
					    });
					  //日期
					  laydate.render({
						   elem: '#checkDate'
						   ,type: 'datetime'
						});
				  }
			});
		}
	});
	
	//监听行单击事件(子表)
	 table.on('row(msSpotCheck)', function(obj){
		$("#detailsTitle").removeClass("layui-hide");
		var orderNumber = obj.data.orderNumber;
		$("#orderNumberText").val(orderNumber);
	  	table.render({
		    elem: '#msSpotCheckDetails'
		    ,url:'${pageContext.request.contextPath }/msSpotCheck/selectMsSpotCheckDetailsListByNumber.do'
		    ,where:{ptNumber: orderNumber}
		    ,toolbar: '#toolbarDemoDetails'
		    ,title: '膜丝抽检详情单'
		    ,limits:[10,20,30]
		    ,cols: [[
		    	{field:'', title:'序号', sort: true, type:'numbers', width: 60}
		    	,{field:'orderNumber', title:'检验批次序号' }
			     ,{field:'msCode', title:'膜丝编号'}
			     ,{field:'mbCode', title:'膜丝捆编号'}
			     ,{field:'msFlux', title:'膜丝通量'}
			     ,{field:'msInner', title:'尺寸内径'}
			     ,{field:'msWall', title:'尺寸壁厚'}
			     ,{field:'msBubble', title:'泡点压力'}
			     ,{field:'msIntensity', title:'强度'}
			     ,{field:'msResult', title:'检测结果'}
			     ,{field:'description', title:'原因说明'}
			     ,{fixed: 'right', title:'操作', toolbar: '#barDemoDetails'}
		    ]]
		    ,page: true
		});
	});
	//头工具栏事件（子表）
	table.on('toolbar(msSpotCheckDetails)', function(obj){
		var checkStatus = table.checkStatus(obj.config.id);
		var orderNumberText = $("#orderNumberText").val();
	    switch(obj.event){
	    	case 'addDetails':
        			var content2 = '<form class="layui-form layui-card-body" id="addFormIdChild">'+
        							'<input value="'+orderNumberText+'" name="orderNumber" class="layui-hide"/>'+
        							'<input value="" id="msid_tdd" name="msid_tdd" class="layui-hide"/>'+
									'<div class="layui-form-item"><label class="layui-form-label">膜丝编码</label>'+
										'<input class="layui-input layui-input-inline" lay-verify="msCode" id="msCode" name="msCode" type="text" value="" placeholder="请扫描膜丝条码" style="width:300px;">'+
										'<div class="layui-inline" style="margin-top: 12px;">'+
											'<font style="color:red; font-size: 24px;">*</font>'+
										'</div>'+
									'</div>'+
									'<div class="layui-form-item"><label class="layui-form-label">膜丝捆编码</label><input readonly class="layui-input" lay-verify="mbCode" id="mbCode" name="mbCode" type="text" value="" style="width:300px;"></div>'+
									'<div class="layui-form-item"><label class="layui-form-label">膜丝通量</label><input class="layui-input" lay-verify="msFlux" id="msFlux" name="msFlux" type="text" value="" style="width:300px;"></div>'+
									'<div class="layui-form-item"><label class="layui-form-label">尺寸内径</label><input class="layui-input" lay-verify="msInner" id="msInner" name="msInner" type="text" value="" style="width:300px;"></div>'+
									'<div class="layui-form-item"><label class="layui-form-label">尺寸壁厚</label><input class="layui-input" lay-verify="msWall" id="msWall" name="msWall" type="text" value="" style="width:300px;"></div>'+
									'<div class="layui-form-item"><label class="layui-form-label">泡水压力</label><input class="layui-input" lay-verify="msBubble" id="msBubble" name="msBubble" type="text" value="" style="width:300px;"></div>'+
									'<div class="layui-form-item"><label class="layui-form-label">强度</label><input class="layui-input" lay-verify="msIntensity" id="msIntensity" name="msIntensity" type="text" value="" style="width:300px;"></div>'+
									'<div class="layui-form-item"><label class="layui-form-label">检测结果</label><input readonly class="layui-input" lay-verify="msResult" id="msResult" name="msResult" type="text" value="" style="width:300px;"></div>'+
									'<div class="layui-form-item"><label class="layui-form-label">原因说明</label><textarea class="layui-textarea" lay-verify="description" id="description" name="description" type="text" value="" style="width:300px;"></textarea></div>'+
							  		'<div class="layui-form-item"><div class="layui-input-block">'+
										'<button id="subBtn2" class="layui-btn layui-btn-blue" lay-submit lay-filter="addformChild">提交</button><button type="reset" id="addResetChild" class="layui-btn layui-btn-primary" style="margin-left:140px">重置</button>'+
									'</div></div>'+
								'</form>';
        			layer.open({
	  					  type: 1 		//Page层类型
	  					  ,area: ['500px', '680px'] //宽  高
	  					  ,title: '新增'
	  					  ,shade: 0.1 	//遮罩透明度
	  					  ,maxmin: true //允许全屏最小化
	  					  ,anim: 1 		//0-6的动画形式，-1不开启
	  					  ,content: content2
	  					  ,success:function(layero, index){
		  						form.render();
		  						var oInput = document.getElementById("msCode");
		  			    		oInput.focus();
		  						this.enterEsc = function(event){
		  				          if(event.keyCode === 13){
		  				            return false; //阻止系统默认回车事件
		  				          }
		  			        	}; 
		  			        $(document).on('keydown', this.enterEsc);	//监听键盘事件，关闭层
		  			        $("#msResult").click(function(){
		  			        	var msFlux = Number($("#msFlux").val());
		  			        	var msInner = Number($("#msInner").val());
		  			        	var msWall = Number($("#msWall").val());
		  			        	var msBubble = Number($("#msBubble").val());
		  			        	var msIntensity = Number($("#msIntensity").val());
	  			        		$.ajax({
	  			        			url:'${pageContext.request.contextPath }/criterion/selectSilkCriterion.do'
	  			        			,type:'post'
	  			        			,dataType:'json'
	  			        			,success:function(data){
	  			        				if((msFlux>=data.fluxDown && msFlux<=data.fluxUp) && (msInner>=data.innerDown && msInner<=data.innerUp) && (msWall>=data.wallDown && msWall<=data.wallUp) && (msBubble>=data.pressureDown && msBubble<=data.pressureUp) && (msIntensity>=data.strengthDown && msIntensity<=data.strengthUp)){
	  			        					$("#msResult").val("合格");
	  			        				}else{
	  			        					$("#msResult").val("不合格");
	  			        				}
	  			        			}
	  			        		})
		  			        })
	  					}
  					});
	      	break;
	    };
	});
	//监听行工具事件（子表）
	table.on('tool(msSpotCheckDetails)', function(obj){
		var data = obj.data;
		if(obj.event === 'delDetails'){
		  layer.confirm('确定删除吗？', function(index){
			var idArr = new Array();
		    var msId = data.msId;
		    idArr[0] = msId;
		    $.ajax({
		    	type:'post',
		    	url:'${pageContext.request.contextPath }/msSpotCheck/delMsSpotCheckArrDetails.do',
		    	data:{"idArr":idArr},
		    	success:function(data){
		    		if(data>0){
		    			toastr.success("删除成功！");
		    			setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
							//关闭模态框
							// 父页面刷新
							window.location.reload();  
						},2000);
		    		}else{
		    			toastr.warning("删除失败！");
		    		}
		    	}
		    		
		    })
		    layer.close(index);
		  });
		}
	});
	/**
     * 表单校验
     */
    form.verify({
    	//value：表单的值、item：表单的DOM对象
    	checkDate: function(value, item){
    		if(value == ''){
    			return '日期不能为空';
    		}
    	},
    	msCode: function(value, item){
    		if(value == ''){
    			return '膜丝条码不能为空';
    		}
    	}
    })
    /**
     * 通用表单提交(AJAX方式)（新增）
     */
    form.on('submit(addform)', function (data) {
    	$("#subBtn1").attr("disabled",true);
    	$.ajax({
			type : "post",
			url : '${pageContext.request.contextPath}/msSpotCheck/insertMsSpotCheck.do',
			data : $("#addFormId").serialize(),
			cache : false,
			async:false
			}).done(
				function(res) {
					if (res == 1) {
						toastr.success('新增成功！');
					}
					setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
						//关闭模态框
						// 父页面刷新
						window.location.reload();  
					},2000);
				}
			).fail(
				function(res) {
					toastr.error('新增失败！');
				}
			)
			return false;
    });
    /**
     * 通用表单提交(AJAX方式)(修改)
     */
    form.on('submit(editform)', function (data) {
    	$.ajax({
			url : '${pageContext.request.contextPath}/msSpotCheck/updateMsSpotCheck.do',
			data : $("#editFormId").serialize(),
			cache : false,
			async:false
			/* 
				success: function (data) {},
				error: function (XMLHttpRequest, textStatus, errorThrown) {},
				beforeSend: function () {},
				complete: function () {} 
			 */
			}).done(
				function(res) {
					if (res == 1) {
						toastr.success('修改成功！');
					}
					setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
						//关闭模态框
						// 父页面刷新
						window.location.reload();  
					},2000);
				}
			).fail(
				function(res) {
					toastr.error('修改失败！');
				}
			)
			return false;
    });
    /**
     * 通用表单提交(AJAX方式)（新增子表）
     */
    form.on('submit(addformChild)', function (data) {
    	$("#subBtn2").attr("disabled",true);
    	$.ajax({
			type : "post",
			url : '${pageContext.request.contextPath}/msSpotCheck/insertMsSpotCheckDetails.do',
			data : $("#addFormIdChild").serialize(),
			cache : false,
			async:false
			}).done(
				function(res) {
					if (res == 1) {
						toastr.success('新增成功！');
					}
					setTimeout(function(){  //使用  setTimeout（）方法设定定时2000毫秒
						//关闭模态框
						// 父页面刷新
						window.location.reload();  
					},2000);
				}
			).fail(
				function(res) {
					toastr.error('新增失败！');
				}
			)
			return false;
    });
    //查看统计表
   $("#statistics").click(function(){
	   layer.open({
	        type: 1 					//Page层类型
	        ,area: ['95%', '600px']   	//宽  高
	        ,title: '膜丝抽检统计表'
	        ,shade: 0.6 				//遮罩透明度
	        ,maxmin: true			    //允许全屏最小化
	        ,anim: 1 					//0-6的动画形式，-1不开启
	        /* ,content: $("#lookupTable2") */
	        ,content: '<table class="layui-hide" id="statisticsTable" lay-filter="statisticsTable"></table>'
	        ,success:function(){
	            layui.use(['table'], function(){
	                var table = layui.table;
	                table.render({
	                    elem: '#statisticsTable'
	                    ,url:'${pageContext.request.contextPath }/msSpotCheck/selectMsSpotCheckStatisticsTable.do'
	                    ,title: '膜丝抽检统计表'
	                    ,limits:[10,20,30]
	                    ,cols: [[
	                        {field:'', title:'序号', sort: true, type:'numbers', width: 60}
	                        ,{field:'msName', title:'膜丝名称'}
	                        ,{field:'msStandard', title:'膜丝规格'}
	                        ,{field:'orderNumber', title:'检验批次序号'}
	                        ,{field:'msFlux', title:'膜丝通量'}
	                        ,{field:'msInner', title:'尺寸内径'}
	                        ,{field:'msWall', title:'尺寸壁厚'}
	                        ,{field:'msBubble', title:'泡点压力'}
	                        ,{field:'msIntensity', title:'强度'}
	                    ]]
	                    ,page: true
	                });
	            });
	        }
		})
					
   })
});
function keyDown(e){
    //IE内核浏览器  
     if (navigator.appName == 'Microsoft Internet Explorer'){  
           var keycode = event.keyCode;  
           var realkey = String.fromCharCode(event.keyCode);  
     }else {//非IE内核浏览器  
           var keycode = e.which;  
           var realkey = String.fromCharCode(e.which);  
     }  
   // console.log('按键码:' + keycode +  '字符: ' + realkey);  

   //监听Enter键  
   if(keycode==13){  
         var msCode = $("#msCode").val();
         if(msCode==''){
		   		
		 }else{
	         $.ajax({
	        	 url:'${pageContext.request.contextPath }/msSpotCheck/selectMbCodeByMsCode.do'
	 				,type:'post'
	 				,data:{"msCode":msCode}
	 				,dataType:'json'
	 				,success:function(data){
	 					if(data == 0){
	 						toastr.warning("膜丝不存在或未绑定！");
	 						/* setTimeout(function(){  //使用  setTimeout（）方法设定定时500毫秒
	 							window.location.reload();  
	 						},500); */
	 						$("#msCode").val("");
	 					}else{
	 						$("#mbCode").val(data.mbscode);
	 						$("#msid_tdd").val(data.msid);
	 					}
	 				}
	         })
		 }
   }  
   
}  
//按键事件
document.onkeydown=keyDown;	
toastr.options.positionClass = 'toast-top-center'; //提示框的位置设置为中上
</script>
</body>
</html>